import sys
import pygame
import game_screen
import title_screen


def change_state(screen):
    global current_screen
    current_screen = screen
    
pygame.mixer.pre_init(44100, -16, 2, 2048)
pygame.init()
pygame.key.set_repeat(50,50)

current_screen = title_screen.TitleScreen()
current_interval = current_screen.interval

leftover = 0.0

while 1:
    
    lasttime = pygame.time.get_ticks()

    current_screen.render();  

    current_screen.process_events(change_state)
    pygame.display.flip()
    elapsed = (pygame.time.get_ticks() - lasttime) / 1000.0 + leftover
	
    while(elapsed > current_interval):
        current_screen.update(current_interval)
        elapsed -= current_interval
    leftover = elapsed
